//
//  KCInviteMessage.m
//  KConnect
//
//  Created on 18/03/09.
//  Copyright 2009 Xtreme Labs Inc. All rights reserved.
//

//Message names
#define kInviteSent             @"ins"
#define kNotificationSent       @"nts"
#define kNotificationEmailSent  @"nes"

#define kSenderUID    @"s"   //Sender UID
#define kRecipientUID @"r"   //Recipient UIDS
#define kTrackingFlag @"u"   //Unique tracking tag
#define kTemplateID   @"t"   //Template ID
#define kSubType1     @"st1" //subtype 1
#define kSubType2     @"st2" //subtype 2

#import "KCSentMessage.h"

@implementation KCSentMessage


- (id)initWithSenderUID:(NSString*)senderUID 
          recipientUIDs:(NSArray*) recipients 
            messageType:(KCSentMessageType) someType
{
  
 
  NSString * rec = [self buildCommaString:recipients];
  NSString * tag = [KCMessage longUUID];
  
  NSDictionary *requiredParameters = [NSDictionary dictionaryWithObjectsAndKeys:
                                     senderUID, kSenderUID, 
                                     tag, kTrackingFlag,                                      
                                     rec, kRecipientUID,
                                     nil];
  
  if(self = [super initWithParameters:requiredParameters])
  {
    type = someType;
  }
  
  return self;
}

- (void)setTemplateID:(NSInteger)idNumber
{
  [self addOptionalParameter:kTemplateID value:[NSString stringWithFormat:@"%d", idNumber]];
}

- (void)setSubType1:(NSString*)subtype
{
  [self addOptionalParameter:kSubType1 value:subtype];  
}

- (void)setSubType2:(NSString*)subtype
{
  [self addOptionalParameter:kSubType2 value:subtype];
}

#pragma mark KCMessage Subclass
- (NSString*)messageType
{
  NSString *stringType = [NSString string];
  
	switch(type)
  {
      case KCSentMessageTypeInvite: 
        stringType = kInviteSent;
        break;
      case KCSentMessageTypeNotification: 
        stringType = kNotificationSent;
        break;
      case KCSentMessageTypeEmail: 
        stringType = kNotificationEmailSent;
        break;
      default:
          break;
  }
  
  return stringType;
}

- (NSArray*)requiredParameters
{
  return [NSArray arrayWithObjects:
          kSenderUID,
          kRecipientUID,
          kTrackingFlag,
          nil];
}

- (NSArray*)optionalParameters
{
	return [NSArray arrayWithObjects:
          kTemplateID,
          kSubType1,
          kSubType2,
          nil];
}

@end
